import { RE } from "../type/re";

interface Re {
  rule: RegExp;
  name?: string;
  tip?: string;
}

export class ReDef {
  static readonly phone: Re = {
    rule: /^1\d{10}$/,
    name: "phone",
    tip: "请输入正确的手机号"
  };
  static readonly weight: Re = {
    rule: /^[+]{0,1}(\d*)$/,
    name: "weight",
    tip: "请输入正整数"
  };
  static readonly days: Re = {
    rule: /^[1-9][0-9]{0,1}$/,
    name: "days",
    tip: "请输入1-99的正整数"
  };
  static readonly nameLength: Re = {
    rule: /^[A-Za-z0-9\u4e00-\u9fa5]{0,32}$/,
    name: "name",
    tip: "允许输入汉字、字母、数字。最大长度32个字符"
  };
  static readonly orgNameLength: Re = {
    rule: /^[A-Za-z0-9\u4e00-\u9fa5（）()]{0,32}$/,
    name: "name",
    tip: "允许输入汉字、字母、数字。最大长度32个字符"
  };
  static readonly remarkLength: Re = {
    rule: /^[\s\S]{0,500}$/,
    name: "remark",
    tip: "允许输入汉字、字母、数字、字符。最大长度500个字符"
  };
  static readonly lengthLimit = (
    start: number,
    end: number,
    required: boolean,
    ruleName: string
  ) => {
    // const msg = required ? "必填输入项," : "非必填输入项,";
    return {
      illegalRule: "[\"\"\'\'<>]",
      rule: "^(.|\\n){" + start + "," + end + "}$",
      name: ruleName,
      tip: "请输入" + start + "-" + end + "个字符,且不能包含英文的单双引号和<>"
    } as RE;
  }
}
